﻿using System.Configuration;
using System.IO;
using TFile.ISA;

namespace TFile.CSA
{
    public class DocumentLibraryService : IDocumentLibraryService
    {
        public void UploadDocument(string fPath, byte[] data)
        {
            string filePath = ConfigurationManager.AppSettings["Documentos"] + fPath;
            FileStream fs = new FileStream(@filePath, FileMode.Create, FileAccess.Write);
            fs.Write(data, 0, data.Length);
            fs.Close();
        }

        public void DeleteDocument(string fPath)
        {
            string filePath = ConfigurationManager.AppSettings["Documentos"] + fPath;
            System.IO.File.Delete(@filePath);
        }


        public byte[] DownloadDocument(string fPath)
        {
            string filePath = ConfigurationManager.AppSettings["Documentos"] + fPath;

            using (FileStream fs = new FileStream(@filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, (int)fs.Length);
                return buffer;
            }
        }
    }
}
